using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Sand : Ground
{
    bool used = false;
    PlayerController player;

    protected override void Awake()
    {
        base.Awake();
        player = FindObjectOfType<PlayerController>();
    }

    public void Disappear()
    {
        if (player.canMoveBlock.IsOverlap) return;
        if(player.transform.position.y<transform.position.y) return;
        if (used) return;
        if (LevelManager.instance.cameraMoving) return;
        MaterialFloatAnimation anim = GetComponent<MaterialFloatAnimation>();
        anim.BindEndAction(0, () => { 
            Destroy(gameObject); 
        });
        anim.Play();
        AudioSource audioSource = GetComponent<AudioSource>();
        if (audioSource.enabled) audioSource.Play();
        used = true;
        BlockBase blockBase = LevelManager.instance.FindLastBlock(transform.position, this);

        if (blockBase!=null)
        {
            blockBase.gameObject.SetActive(true);
        }

        gameObject.layer = 0;
        LevelManager.instance.BuildNavMesh();
        if(CameraController.cameralook == CameraLook.Right)
        {
            gameObject.transform.position += Vector3.right * 1;
        }
        else if(CameraController.cameralook == CameraLook.Forward)
        {
            gameObject.transform.position += Vector3.back * 1;
        }
        else if (CameraController.cameralook == CameraLook.Top)
        {
            gameObject.transform.position += Vector3.up * 1;
        }
    }
}
